
!  --------------------------------------------------
!  Silverfrost FTN95 for Microsoft Visual Studio
!  Free Format FTN95 Source File
!
!  --------------------------------------------------
  
module MetodeBagiDua
use aps_top
!program BagiDua
!implicit none
!real*8 epsilon, answer, x1, x2
!integer*2 iteration
!parameter (epsilon = 0.00001)
!parameter (x1=0.001)
!parameter (x2=1.55)
!call bagidua (epsilon,x1,x2,answer,iteration)
!print*,answer
!print*,iteration
!pause
!end
contains

subroutine bagidua (eps,a,b,jawaban,count)
implicit none 
real*8 a,b,c,jawaban,eps,f,deltaN,temp1,temp2
integer*2 count
temp1 = a
temp2 = b

count = 0
deltaN = abs (temp1-temp2)
c = (temp1+temp2)/2

do while (deltaN > eps )
c = (temp1+temp2)/2
jawaban = c
if ((f(temp1)*f(c)) < 0) then
    temp2 = c
    write (*,'(A)') temp2
    deltaN = abs (temp1-temp2)
else 
    temp1 = c
    deltaN = abs (temp1-temp2)
end if
count = count + 1
end do
jawaban = c
end subroutine bagidua

real*8 function f(x)
implicit none
real*8 x
if (u(1) /= 0) then
f = ((x*((2.1-(0.5*x))**0.5)) / ((1-x)*((1.1-(0.5*x))**0.5))) - 3.69
else if (u(2) /= 0) then
f = tan(x)-x+1
else if (u(3) /= 0) then
f = (0.5*exp(x/3)) - sin(x)
end if
end function f
!real*8 function f(x)
!implicit none
!real*8 x
!f = ((x*((2.1-(0.5*x))**0.5)) / ((1-x)*((1.1-(0.5*x))**0.5))) - 3.69
!f = tan(x)-x+1
!f = (0.5*exp(x/3)) - sin(x)
!end

end MetodeBagiDua